//Tue Apr 20 14:03:14 CDT 2010
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

const int MAX = 0;
long long N;

long long solve(long long a)
{
	long long cnt = 0;
	long long i, len;
	long long tt = 9;
	for (i = 1;; i++)
	{
		if (cnt + tt >= a)
		{
			len = i;
			break;
		}
		cnt += tt;
		if (i % 2 == 0)
			tt *= 10;
	}
	a -= cnt;
	long long half = 1;
	for (i = 2; i <= (len + 1) / 2; i++)
		half *= 10;
	half += a - 1;
	long long res = half;
	if (len & 1)
		half /= 10;
	while (half)
	{
		res = res * 10 + half % 10;
		half /= 10;
	}
	return res;
}

int main()
{
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	while (cin >> N && N)
	{
		cout << solve(N) << endl;
	}
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}
